package com.wiiss.ams.util.http;

import cn.hutool.json.JSONObject;
import com.wiiss.ams.cron.Cron;
import com.wiiss.ams.cron.task.action.collecting_handling_cron_action.collector.Collector;

import java.util.List;

public class HttpCollector implements Collector {

    private HttpRequestCreator httpRequestCreator;

    private HttpRequestExecutor httpRequestExecutor;

    private HttpResponseExtractor httpResponseExtractor;

    public HttpCollector(HttpRequestCreator httpRequestCreator, HttpRequestExecutor httpRequestExecutor, HttpResponseExtractor httpResponseExtractor) {
        super();
        this.httpRequestCreator = httpRequestCreator;
        this.httpRequestExecutor = httpRequestExecutor;
        this.httpResponseExtractor = httpResponseExtractor;
    }

    @Override
    public List<JSONObject> collect(Cron cron) {
        return httpResponseExtractor.extract(httpRequestExecutor.execute(httpRequestCreator.create(cron)));
    }

}
